package com.xyre.client.framework.util;

/**
 * 检测是否是快速点击的帮助类
 * 
 * @author 792793182@qq.com 2015-09-07
 *
 */
public final class TimeIntervalChecker {

	private static final long WAIT_TIME = 1000;

	private long waitTime = WAIT_TIME;

	private long lastTime = 0;
	
	public TimeIntervalChecker() {

	}

	/**
	 * 构造方法
	 * @param waitTime 等待时间
	 */
	public TimeIntervalChecker(long waitTime) {
		this.waitTime = waitTime;
	}

	/**
	 * 是否是小于给定的值
	 */
	public boolean isLessThan() {
		long now = System.currentTimeMillis();
		//这种情况是修改了系统时间，将系统时间改成现在时间的前面
		if (now - lastTime < 0) {
			lastTime = 0;
		} else if (now - lastTime < waitTime) {
			return true;
		}
		lastTime = System.currentTimeMillis();
		return false;
	}

	public boolean isMoreThan() {
		long now = System.currentTimeMillis();
		//这种情况是修改了系统时间，将系统时间改成现在时间的前面
		if (now - lastTime < 0) {
			lastTime = 0;
		} else if (now - lastTime >= waitTime) {
			lastTime = System.currentTimeMillis();
			return true;
		}

		return false;
	}
}
